/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package extension.room.tienlen;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import extension.game.room.GameResponse;
import extension.game.room.RoomExtension;
import java.util.List;
import log.Debug;

/**
 *
 * @author daz
 */
public class TienlenResponse extends GameResponse {

    public TienlenResponse(RoomExtension ext) {
        super(ext);
    }

    public void sendTableInfo(List<String> listNames, List<Long> listMoneys, List<Integer> listStates, long betMoney, boolean isPlay, int tableHost, int seatPos,
            String playerName, long playerMoney, int level, String levelName, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putUtfStringArray(TienlenFlag.LIST_NAMES, listNames);
        resObj.putLongArray(TienlenFlag.LIST_MONEY, listMoneys);
        resObj.putIntArray(TienlenFlag.LIST_STATES, listStates);
        resObj.putLong(TienlenFlag.BET_MONEY, betMoney);
        if (isPlay) {
            resObj.putInt(TienlenFlag.IS_PLAY, 1);
        } else {
            resObj.putInt(TienlenFlag.IS_PLAY, 0);
        }
        resObj.putInt(TienlenFlag.SEAT_POS, seatPos);
        resObj.putInt(TienlenFlag.TABLE_HOST, tableHost);
        //player info
        resObj.putUtfString(TienlenFlag.PLAYER_NAME, playerName);
        resObj.putLong(TienlenFlag.PLAYER_MONEY, playerMoney);
        resObj.putInt(TienlenFlag.PLAYER_LEVEL, level);
        resObj.putUtfString(TienlenFlag.PLAYER_LEVEL_NAME, levelName);
        ext.send(TienlenCommand.ROOM_INFO, resObj, user);
        log(resObj);
    }

    public void sendTableInfo(List<String> listNames, List<Long> listMoneys, List<Integer> listStates,
            long betMoney, boolean isPlay, int tableHost, int seatPos, long totalMoney,
            List<Integer> listNumberCard,
            User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putUtfStringArray(TienlenFlag.LIST_NAMES, listNames);
        resObj.putLongArray(TienlenFlag.LIST_MONEY, listMoneys);
        resObj.putIntArray(TienlenFlag.LIST_STATES, listStates);
        resObj.putLong(TienlenFlag.BET_MONEY, betMoney);
        resObj.putLong("total_money", totalMoney);
        if (isPlay) {
            resObj.putInt(TienlenFlag.IS_PLAY, 1);
        } else {
            resObj.putInt(TienlenFlag.IS_PLAY, 0);
        }
        resObj.putInt(TienlenFlag.SEAT_POS, seatPos);
        resObj.putInt(TienlenFlag.TABLE_HOST, tableHost);
        resObj.putIntArray(TienlenFlag.PLAYER_NUMBER_CARD, listNumberCard);
        resObj.putUtfString(TienlenFlag.PLAYER_NAME, user.getName());
//        resObj.putLong(TienlenFlag.PLAYER_MONEY, playerMoney);
        ext.send(TienlenCommand.ROOM_INFO, resObj, user);
        log(resObj);
    }

    public void sendTableInfo(List<String> listNames, List<Integer> listMoneys, List<Integer> listStates,
            int betMoney, boolean isPlay, int tableHost, int seatPos,
            List<Integer> listNumberCard,
            User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putUtfStringArray(TienlenFlag.LIST_NAMES, listNames);
        resObj.putIntArray(TienlenFlag.LIST_MONEY, listMoneys);
        resObj.putIntArray(TienlenFlag.LIST_STATES, listStates);
        resObj.putInt(TienlenFlag.BET_MONEY, betMoney);
        if (isPlay) {
            resObj.putInt(TienlenFlag.IS_PLAY, 1);
        } else {
            resObj.putInt(TienlenFlag.IS_PLAY, 0);
        }
        resObj.putInt(TienlenFlag.SEAT_POS, seatPos);
        resObj.putInt(TienlenFlag.TABLE_HOST, tableHost);
        resObj.putIntArray(TienlenFlag.PLAYER_NUMBER_CARD, listNumberCard);
        ext.send(TienlenCommand.ROOM_INFO, resObj, user);
        Debug.d(resObj.getDump());
    }

    public void sendUserLeave(int leaveId, boolean isContinue, int numberPlayers) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TienlenFlag.NUMBER_PLAYERS, numberPlayers);
        resObj.putInt(TienlenFlag.LEAVE_ID, leaveId);
        resObj.putInt(TienlenFlag.IS_PLAY, isContinue ? 1 : 0);

        ext.send(TienlenCommand.PLAYER_LEAVE, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendDealCard(List<Integer> listCards, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(TienlenFlag.LIST_CARDS, listCards);
        ext.send(TienlenCommand.DEAL_CARD, resObj, user);
        log(resObj);
    }

    void sendFirstTurn(int gameTurn, int lastBlock, List<User> userList) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TienlenFlag.FIRST_TURN, gameTurn);
        resObj.putInt(TienlenFlag.LAST_BLOCK, lastBlock);
        ext.send(TienlenCommand.FIRST_TURN, resObj, userList);
        log(resObj);
    }

    public void sendFightCard(List<Integer> listCards, int gameTurn, int canFight, List<User> listSend) {
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(TienlenFlag.LIST_CARDS, listCards);
        resObj.putInt(TienlenFlag.PLAYER_FIGHT, gameTurn);
        resObj.putInt(TienlenFlag.CAN_FIGHT, canFight);
        ext.send(TienlenCommand.FIGHT_CARD, resObj, listSend);
        log(resObj);
    }

    void sendGameTurn(int gameTurn, int lastBlock, List<Integer> listBlock) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TienlenFlag.GAME_TURN, gameTurn);
        resObj.putInt(TienlenFlag.LAST_BLOCK, lastBlock);
        resObj.putIntArray(TienlenFlag.SUGGEST_CARD, listBlock);
        ext.send(TienlenCommand.GAME_TURN, resObj, ext.getParentRoom().getUserList());
        log(resObj);
    }

    void sendFinishRound() {
        ext.send(TienlenCommand.NEW_ROUND, null, ext.getParentRoom().getUserList());
    }

    void sendSkipTurn(int skipId) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TienlenFlag.SKIP_PLAYER, skipId);
        ext.send(TienlenCommand.SKIP_TURN, resObj, ext.getParentRoom().getUserList());
        Debug.d(TienlenFlag.SKIP_PLAYER + ":" + skipId);

    }

    public void sendFightAll(int rank, int playerFinish, int numberView) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TienlenFlag.NUMBER_VIEW, numberView);
        resObj.putInt(TienlenFlag.PLAYER_RANK, rank);
        resObj.putInt(TienlenFlag.PLAYER_FINISH, playerFinish);
        ext.send(TienlenCommand.FIGHT_ALL, resObj, ext.getParentRoom().getUserList());

    }

    void sendFinishMatch(List<Long> moneyResult, List<Long> playerMoney, int playerWin, int tableHost, int numberPlayers) {
        ISFSObject resObj = new SFSObject();
        resObj.putLongArray(TienlenFlag.MONEY_RESULT, moneyResult);
        resObj.putLongArray(TienlenFlag.PLAYER_MONEY, playerMoney);
        resObj.putInt(TienlenFlag.PLAYER_WIN, playerWin);
        resObj.putInt(TienlenFlag.TABLE_HOST, tableHost);
        resObj.putInt(TienlenFlag.NUMBER_PLAYERS, numberPlayers);
        ext.send(TienlenCommand.FINISH_MATCH, resObj, ext.getParentRoom().getUserList());
        Debug.d("send money result");
    }

    public void sendFightCard(int canFight, User user) {
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TienlenFlag.CAN_FIGHT, canFight);
        ext.send(TienlenCommand.FIGHT_CARD, resObj, user);
    }

    void sendPlayerOut(String name, int seatPos) {
        ISFSObject resObj = new SFSObject();
        resObj.putUtfString(TienlenFlag.PLAYER_NAME, name);
        resObj.putInt(TienlenFlag.PLAYER_SEAT, seatPos);
        ext.send(TienlenCommand.PLAYER_OUT, resObj, ext.getParentRoom().getUserList());
    }

//    void sendPlayerKick(String name, int seatPos) {
//        ISFSObject resObj = new SFSObject();
//        resObj.putUtfString("player_name", name);
//        resObj.putInt("player_seat", seatPos);
//        ext.send(TienlenCommand.KICK, resObj, ext.getParentRoom().getUserList());
//        log(resObj);
//    }
    void sendMoneyChange(long moneyChange, int playerWin, long playerWinMoney, int playerLost, long playerLostMoney) {
        ISFSObject resObj = new SFSObject();
        resObj.putLong(TienlenFlag.MONEY_CHANGE, moneyChange);
        resObj.putInt(TienlenFlag.PLAYER_WIN, playerWin);
        resObj.putLong(TienlenFlag.PLAYER_WIN_MONEY, playerWinMoney);
        resObj.putInt(TienlenFlag.PLAYER_LOST, playerLost);
        resObj.putLong(TienlenFlag.PLAYER_LOST_MONEY, playerLostMoney);
        ext.send(TienlenCommand.MONEY_CHANGE, resObj, ext.getParentRoom().getUserList());
    }

    void sendUpdateTableHost(int newTableHost, int isPlay) {
        Debug.d("send update table host");
        ISFSObject resObj = new SFSObject();
        resObj.putInt(TienlenFlag.TABLE_HOST, newTableHost);
        resObj.putInt(TienlenFlag.IS_PLAY, isPlay);
        ext.send(TienlenCommand.UPDATE_TABLE_HOST, resObj, ext.getParentRoom().getUserList());
    }

    void sendUpdateRank(List<Integer> listRank) {
        ISFSObject resObj = new SFSObject();
        resObj.putIntArray(TienlenFlag.LIST_RANK, listRank);
        ext.send(TienlenCommand.UPDATE_RANK, resObj, ext.getParentRoom().getUserList());
    }
}
